#A first python script
import sys
import math
import random
num = 1
string = '1'
num2 = int(string)
print(type(string))
print(type(num))
print(num + num2)

words = "words" * 3
print(words)

friends = 'friends'

find_friends = friends[0] + friends[2:4] + friends[-3:-1]
print(find_friends)

phone_number = '1843-808-8044'
hinding_number = phone_number.replace(phone_number[:9], '*' * 9)

print(hinding_number)

search = '168'
num_a = '1386-168-0006'
num_b = '1681-222-0006'

print(search + ' is at ' + str(num_a.find(search)) + ' to ' + str(num_a.find(search) + len(search)) + ' of num_a')
print(search + ' is at ' + str(num_b.find(search)) + ' to ' + str(num_b.find(search) + len(search)) + ' of num_a')

# 函数定义
def fahrenheit_converter(C):
    fahrenheit = C * 9/5 + 32
    return str(fahrenheit) + 'F'
C2F = fahrenheit_converter(35)
print(C2F)

def convert_gToKg(g):
    kg = g / 1000
    return kg
kg = convert_gToKg(1000)
print(kg)

def cal_tangle_res(a, b):
    c = math.sqrt(a ** 2 + b ** 2)
    print('The right triangle third side\'s length is',c)
    

cal_tangle_res(3,4)

# def test_create(name, msg):
#     path = '../MyCode/python_project/Script/'
#     full_path = path + name + '.txt'
#     file = open(full_path, 'w')
#     file.write(msg)
#     file.close()
#     print('Done')
# test_create('hello', 'hello world')

list_l = ['hello', True, 12, 'world']
list_l.append('hhh')
print(list_l[0], list_l[-1])

flag = 'hello' in list_l
print(flag)

flag2 = 2 < 3 and 3 < 4
print(flag2)

flag3 = 2 is int
print(flag3)

print(type(2))


def account_login():
    while True:
        password = input('password: ')
        if password == '12345':
            print('success login!')
            break
        else:
            print('wrong')

account_login()

for every_letter in 'hello world':
    print(every_letter)

for num in range(1,11):
    print(str(num) + ' + 1 = ', num + 1)

songsList = ['Holy Diver', 'Thunderstruck', 'Rebel Rebel']
for song in songsList:
    if song == 'Holy Diver':
        print(song, '-Dio')
    elif song == 'Thunderstruck':
        print(song, 'AC/DC')
    elif song == 'Rebel Rebel':
        print(song, '-David Bowide')
#{} 作为占位符，用于标记字符串中需要插入值的位置。在调用 format() 方法时，会按照占位符出现的顺序，依次将传入的参数填充进去。
for i in range(1, 10):
    for j in range(1, 10):
        print('{} X {} = {}'.format(i,j,i*j))

while True:
    print('hello')

count = 0
while count < 3:
    print('hello')
    count += 1

password_list = ['*#*#', '12345']

def account_login():
    tries = 3
    while tries > 0:
        password = input('password: ')
        password_correct = password == password_list[-1]
        password_reset = password == password_list[0]
        
        if password_correct:
            print('Login sucess!')
        elif password_reset:
            new_password = input('Enter a new password: ')
            password_list.append(new_password)  # 修正拼写错误
            print('password has changed sucessfully!')
            account_login()
        else:
            print('wrong password or invalid input!')
            tries = tries - 1
            print(tries, 'times left')
    else:
        print('your account has been suspended')
account_login()


def roll_dice(numbers = 3, points = None):
    print('<<<<ROLL THE DICE!>>>>')
    if points is None:
        points = []
    while numbers > 0:
        point = random.randrange(1,7)
        points.append(point)
        numbers -= 1
    return points

def roll_result(total):  # 修正函数名拼写错误
    isBig = 11 <= total <= 18
    isSmall = 3 <= total <= 10
    if isBig:
        return 'Big'
    elif isSmall:
        return 'Small'

def start_game():
    print('<<<<GAME START!>>>>')
    choices = ['Big', 'Small']
    your_choice = input('Big or Small: ')
    if your_choice in choices:  # 修正变量名拼写错误
        points = roll_dice()
        total = sum(points)
        youWin = your_choice == roll_result(total)
        if youWin:
            print('the points are', points, 'you win!')
        else:
            print('the points are', points, 'you lose!')
    else:
        print('Invalid words')
        start_game()
    
    start_game()

    